<?php
include_once('_PATH.php');
require_once($_CLASSPATH . '/persistence/PersistenceBroker.class.php');

class UserPersistence extends PersistenceBroker {

	function createUser ( $_name ) {
		$query = "INSERT INTO fb_user (nm_user, fl_active) VALUES ('". $_name . "', 1)";

		$this->broker->execute( $query );

		$query = "SELECT MAX( cd_user ) AS uid FROM fb_user WHERE nm_user = '" . $_name . "'";
		$rsGenId = & $this->broker->executeQuery( $query );

		if ( $uidarr = & $this->broker->fecthAssoc( $rsGenId ) )
			$uid = $uidarr['uid'];

		$this->broker->closeConnection( );

		return $uid;
	}

	function associateSocialUser( $_uid, $_socialNetId, $_fbuid) {
		$query = "INSERT INTO fb_socialuser (cd_socialnetwork, cd_user, id_socialuser) VALUES ( $_socialNetId , $_uid , '". $_fbuid . "' )";
		echo $query;
		if ( ! $this->broker->execute( $query ) )
			echo mysql_error();
		$this->broker->closeConnection( );
	}

	function getUserBySociaId( $_socialNetId , $_socialId ) {
		$query = "SELECT MAX(cd_user) AS uid FROM fb_socialuser WHERE cd_socialnetwork = " . $_socialNetId . " AND id_socialuser = '" . $_socialId . "'";

		$rsGenId = & $this->broker->executeQuery( $query );

		if ( $uidarr = & $this->broker->fecthAssoc( $rsGenId ) )
			$uid = $uidarr['uid'];

		$this->broker->closeConnection( );

		return $uid;
	}
}
?>